package com.hnkywl.sts.service.taskdeal;

import com.hnkywl.sts.dao.base.BmDao;
import com.hnkywl.sts.dao.bg.BgWzbmDao;
import com.hnkywl.sts.dao.sys.*;
import com.hnkywl.sts.entity.sys.*;
import com.hnkywl.sts.service.bg.BgWzbmService;
import com.hnkywl.sts.webservice.bg.request.BgWzbm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * Created with IntelliJ IDEA.
 * User: ccr
 * Date: 13-9-13
 * Time: 上午11:33
 * To change this template use File | Settings | File Templates.
 */
@Service
public class DoBgwzbmSync {
    private BgWzbmDao bgWzbmDao;
    private BgWzbmService bgWzbmService;
    //手动执行方法
    public void doBgwzbmSync(){
        List<BgWzbm> bgWzbmList = new ArrayList<BgWzbm>();
        bgWzbmList.addAll(bgWzbmDao.findAll());
        InterfaceSave(bgWzbmList);
    }

    @Transactional(readOnly=true)
    public List<BgWzbm> findBgWzbmList(){
        List<BgWzbm> bgWzbmList = new ArrayList<BgWzbm>();
        bgWzbmList.addAll(bgWzbmDao.findAll());
        return bgWzbmList;
    }
    public void InterfaceSave(List<BgWzbm> bgWzbmList){
        for (BgWzbm bgWzbm : bgWzbmList){
            try{
                switch (bgWzbm.getGrade()) {
                    case 1:
                        if(bgWzbm.getOpt() == 0){
//                            bgWzbmService.addYjwzbm(bgWzbm);
                        } else if(bgWzbm.getOpt() == 1){
//                            bgWzbmService.updateYjwzbm(bgWzbm);
                        } else {
//                            bgWzbmService.destroyYjwzbm(bgWzbm);
                        }
                        break;
                    case 2:
                        if(bgWzbm.getOpt() == 0){
//                            bgWzbmService.addRjwzbm(bgWzbm);
                        } else if(bgWzbm.getOpt() == 1){
//                            bgWzbmService.updateRjwzbm(bgWzbm);
                        } else {
//                            bgWzbmService.destroyRjwzbm(bgWzbm);
                        }
                        break;
                    case 3:
                        if(bgWzbm.getOpt() == 0){
//                            bgWzbmService.addPm(bgWzbm);
                        } else if(bgWzbm.getOpt() == 1){
//                            bgWzbmService.updatePm(bgWzbm);
                        } else {
//                            bgWzbmService.destroyPm(bgWzbm);
                        }
                        break;
                    case 4:
                        if(bgWzbm.getOpt() == 0){
//                            bgWzbmService.addGg(bgWzbm);
                        } else if(bgWzbm.getOpt() == 1){
//                            bgWzbmService.updateGg(bgWzbm);
                        } else {
//                            bgWzbmService.destroyGg(bgWzbm);
                        }
                }
                bgWzbm.setLastUpdated(new Date());
                bgWzbm.setZt(2);
            } catch (Exception e){
                e.printStackTrace();
                bgWzbm.setLastUpdated(new Date());
                bgWzbm.setZt(3);
                bgWzbm.setExcept(e.getMessage());
            }
//            bgWzbmService.save(bgWzbm);
        }
    }

    @Autowired
    public void setBgWzbmDao(BgWzbmDao bgWzbmDao) {
        this.bgWzbmDao = bgWzbmDao;
    }
    @Autowired
    public void setBgWzbmService(BgWzbmService bgWzbmService) {
        this.bgWzbmService = bgWzbmService;
    }
}
